package tech.eyao.hs60x.push;

import cn.jiguang.common.resp.APIConnectionException;
import cn.jiguang.common.resp.APIRequestException;
import cn.jpush.api.JPushClient;
import cn.jpush.api.push.PushResult;
import cn.jpush.api.push.model.Platform;
import cn.jpush.api.push.model.PushPayload;
import cn.jpush.api.push.model.audience.Audience;
import cn.jpush.api.push.model.notification.Notification;
import tech.eyao.hs60x.common.CommonConstants;

public class TestPush {

	public static final String ALERT = "Test from API Example - alert";

	public static PushPayload buildPushObject_all_all_alert() {
		return PushPayload.alertAll(ALERT);
	}

	public static PushPayload buildPushObject_all_alias_alert() {
		return PushPayload.newBuilder().setPlatform(Platform.all()).setAudience(Audience.alias("alias1"))
				.setNotification(Notification.alert(ALERT)).build();
	}

	public static void main(String[] args) {
		JPushClient jPushClient = new JPushClient(CommonConstants.MASTER_SECRET, CommonConstants.APPKEY);

		for (int i = 0; i < 1; i++) {
			PushResult result;
			try {
				result = jPushClient.sendPush(buildPushObject_all_alias_alert());
				System.out.println(result.getResponseCode() + " " + result.msg_id);
			} catch (APIConnectionException e) {
				e.printStackTrace();
			} catch (APIRequestException e) {
				e.printStackTrace();
			}
		}
		jPushClient.close();
	}
}
